package com.example.demo.service.impl;

import com.example.demo.mapper.SpringBootMapper;
import com.example.demo.model.Material;
import com.example.demo.model.vo.MaterialAddVo;
import com.example.demo.service.SpringBootService;
import com.example.demo.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by 86151 on 2018/12/24.
 */
@Service
@Slf4j
public class SpringBootServiceImpl implements SpringBootService {

@Autowired
private SpringBootMapper springBootMapper;

    @Override
    public List<Material> queryAll() {
        return springBootMapper.queryAll();
    }

    @Override
    public List<Material> batchQueryAllByIds(List<Integer> ids) {
        return springBootMapper.zhuJieBatchQueryAllByIds(ids);
    }

    @Override
    public List<Material> batchAddMaterial(List<Material> material) {
        springBootMapper.batchAddMaterial(material);
        return material;
    }
    @Override
    public List<Material> batchUpdateMaterial(List<Material> material) {
        springBootMapper.batchUpdateMaterial(material);
        return material;
    }

    /**
     @Transactional只能作用与对数据库的操作，当数据库出现问题时会进行回滚，保证事务的一致性。
     */
    @Override
    @Transactional
    public Result<MaterialAddVo> addMaterial(MaterialAddVo materialAddVo)throws Exception {
        Material material =new Material();
        log.info("=================================我是测试日志=====================================");
        log.debug("===============================我是错误日志=========================");
        BeanUtils.copyProperties(materialAddVo,material);
         springBootMapper.addMaterial(material);



//         throw new SQLException();
         springBootMapper.addMaterialTest(material);
//         throw new Exception();

        return null;
    }


}
